package com.android.v1.ordertracking;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.app.Activity;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.android.v1.ordertracking.utils.AsyncSoapHttp;
import com.android.v1.ordertracking.utils.Common;
import com.android.v1.ordertracking.utils.SharedPreferenceUtils;

public class IndividualityActivity extends Activity {
	String mDeviceID;
	EditText editTextWebServiceIp;
	TextView textViewDerviceId;
	TextView isError;
	
	private Button back;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_gexing);
		
		editTextWebServiceIp = (EditText)findViewById(R.id.editWebserviceIp);
		String url =SharedPreferenceUtils.getString(this, Common.SP_NAME, Common.URL);
		if(url ==null || url.equals("")){
			editTextWebServiceIp.setText("http://192.168.1.109/YWE_DB/");
		}else{
			editTextWebServiceIp.setText(url);
		}
		
		textViewDerviceId = (TextView)findViewById(R.id.editDeviceID);
		isError = (TextView)findViewById(R.id.isError);
		
		mDeviceID = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);
		
		textViewDerviceId.setText(mDeviceID);
		
		back = (Button)findViewById(R.id.back);
		 back.setOnClickListener(new View.OnClickListener() {

	            @Override
	            public void onClick(View arg0) {
	                IndividualityActivity.this.finish();
	            }
	        });
		
		editTextWebServiceIp.addTextChangedListener(new TextWatcher() {
			
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				
			}
			
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				
			}
			
			@Override
			public void afterTextChanged(Editable s) {
				if(!s.toString().trim().equals("")){
					isError.setVisibility(View.GONE);
					SharedPreferenceUtils.putString(getApplicationContext(), Common.SP_NAME, Common.URL, s.toString().trim());
				
			}}
		});
	}

}
